using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace BF
{
    public class MonoPoolRoot : MonoSingleton<MonoPoolRoot>
    {
        protected override bool isDontDestroy => true;

        public float time { get; private set; }

        private List<IPool> _pools = new List<IPool>();

        private void Update()
        {
            this.time = Time.time;
        }

        internal void RegisterPool<T>(MonoPool<T> pool) where T : MonoRecycleItem
        {
            _pools.Add(pool);
        }

        internal void DeregisterPool<T>(MonoPool<T> pool) where T : MonoRecycleItem
        {
            _pools.Remove(pool);
        }

        /// <summary>
        /// 删除池中所有缓存对象,不包括正在使用的
        /// </summary>
        public void ClearAllMonoPoolItemCache()
        {
            foreach (IPool pool in _pools)
            {
                pool.DestroyAllItemCache();
            }
        }

        public void ClearAllPool()
        {
            for (int i = _pools.Count - 1; i >= 0; i--)
            {
                _pools[i].Dispose();
            }
        }
    }
}
